package com.skillworld.webapp.model.bag;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.skillworld.webapp.model.gamemap.GameMap;
import com.skillworld.webapp.model.util.dao.GenericDaoHibernate;

@Repository("ItemRecordDao")
public class ItemRecordDaoHibernate extends GenericDaoHibernate<ItemRecord,Long> implements ItemRecordDao
{

    @SuppressWarnings("unchecked")
    public List<ItemRecord> findByInventoryAndItem(Long inventory, Long item)
    {
        List<ItemRecord> lr = null;
        //
        
        lr = getSession().createQuery("SELECT itemR FROM ItemRecord itemR "
                         +" WHERE itemR.item in" 
                         +" (SELECT it FROM Item it WHERE it.itemId = :item)"
                         +" AND itemR.inventory in" 
                         +" (SELECT inv FROM Inventory inv WHERE inv.inventoryId = :inventory)")
                         .setParameter("item", item)
                         .setParameter("inventory", inventory)
                         .list();
        return lr;
    }
    
}
